// JavaScript Document

function getXMLHttpRequestObject()
{
	var ajax = false;
	
	if(window.XMLHttpRequest) {
		ajax = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				alert("Request failed.");
			}
		}
	}
	
	return ajax;
}

function initializePage()
{
	var ajax = getXMLHttpRequestObject();
	if(ajax) {
		if(document.getElementById("results")) {
			document.getElementById("hotel_form").onsubmit =
				function() {
					var tbl = document.getElementById('tbl').value;
					ajax.open('get', 'm8_results_ajax.php?tbl='
						+ encodeURIComponent(tbl));
					ajax.onreadystatechange = function() {
						handleResponse(ajax);
					}
					
					ajax.send(null);
					return false;
				}
		}
	}
	
	return false;
}

function handleResponse(ajax) {
	if(ajax.readyState == 4) {
		if((ajax.status == 200) || (ajax.status == 304)) {
			var results = document.getElementById('results');
			results.innerHTML = ajax.responseText;
			results.style.display = 'block';
		}
		else {
			documentgetElementById('hotel_form').submit();
		}
	}
}

window.addEventListener("load", initializePage, false);